import { API_LIST } from '../../../Api/Api'
import { commonTableList, BuiltInData } from '../Common/common'
import { AddDataButton, ModDataButton, DelDataButton, OpenSelection } from '../Common/options'
import { PersonTypeTree } from '../Common/Conversion'

export const Attendance = async ({ url, OptionsEvent, ClientData, Permission }) => {
    const parentUuid = await PersonTypeTree()
    let data = {
        pageSize: 10,
        params: { pageIndex: 1, OAttendanceTime: 'desc@1' },
        get: API_LIST()[`get${url}`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        options: [
            <OpenSelection
                OptionsEvent={OptionsEvent}
                title="批量删除"
                type="primary"
                danger
                data={{
                    type: 'SelectionDelete',
                    url: 'posAttendancesBatchRemoveAttendances',
                }}
            />,
        ],
        columns: [
            { ...commonTableList.SearchSort, selectType: 'Attendance' },
            commonTableList.uuid,
            {
                dataIndex: 'personTypeUuid',
                title: '人员类别',
                valueType: 'treeSelect',
                fieldProps: {
                    options: parentUuid,
                    fieldNames: { label: 'tableName', value: 'uuid' },
                },
                rules: true,
                hideInTable: true,
                hideInSearch: true,
                width: 150,
            },
            {
                dataIndex: 'personName',
                title: '姓名',
                valueType: 'input',
                width: 150,
            },
            { ...commonTableList.organizationUuid, valueEnum: ClientData.organization },
            {
                dataIndex: 'mobile',
                title: '手机号码',
                valueType: 'hidden',
                width: 150,
            },
            {
                dataIndex: 'attendanceTime',
                title: '考勤日期',
                valueType: 'Date',
                showTime: true,
                rules: true,
                width: 150,
                hideInSearch: true,
            },
            // {
            //     dataIndex: 'temperature',
            //     title: '温度',
            //     valueType: 'inputNumber',
            //     width: 150,
            //     hideInSearch: true,
            // },

            // {
            //     dataIndex: 'overTemperatureType',
            //     title: '超温类别',
            //     search: true,
            //     valueType: 'select',
            //     valueEnum: {},
            //     width: 150,
            //     hideInSearch: true,
            // },
            {
                dataIndex: 'inOrOut',
                title: '进或出',
                valueType: 'select',
                valueEnum: BuiltInData.inOrOut,
                width: 150,
                hideInSearch: true,
            },
            {
                dataIndex: 'auditStatus',
                title: '审核状态',
                valueType: 'select',
                valueEnum: BuiltInData.Pass,
                width: 150,
                hideInSearch: true,
            },
            {
                dataIndex: 'lng',
                title: '经度',
                valueType: 'inputNumber',
                width: 150,
                hideInSearch: true,
            },
            {
                dataIndex: 'lat',
                title: '纬度',
                valueType: 'inputNumber',
                width: 150,
                hideInSearch: true,
            },
            {
                dataIndex: 'address',
                title: '考勤地址',
                valueType: 'textarea',
                width: 150,
                hideInSearch: true,
            },
            {
                dataIndex: 'laborCompany',
                title: '劳务公司',
                valueType: 'input',
                hideInAdded: true,
                hideInModify: true,
                hideInTable: true,
            },
            {
                dataIndex: 'idCard',
                title: '身份证号',
                valueType: 'input',
                hideInAdded: true,
                hideInModify: true,
                hideInTable: true,
            },
            {
                dataIndex: 'workType',
                title: '工种',
                valueType: 'input',
                hideInAdded: true,
                hideInModify: true,
                hideInTable: true,
            },
            {
                dataIndex: 'departmentUuid',
                title: '部门',
                valueType: 'select',
                valueEnum: ClientData.dictionary['a2891f3b-3811-4b8b-8dbb-832096e3174e'],
                hideInAdded: true,
                hideInModify: true,
                hideInTable: true,
            },
            {
                dataIndex: 'rankUuid',
                title: '职务级别',
                valueType: 'select',
                valueEnum: ClientData.dictionary['d83de24e-191d-4646-b742-55ad694a3747'],
                hideInAdded: true,
                hideInModify: true,
                hideInTable: true,
            },
            {
                dataIndex: 'categoryUuid',
                title: '人员性质',
                valueType: 'select',
                valueEnum: ClientData.dictionary['51297964-6295-475a-8219-d3f9a4568fe6'],
                hideInAdded: true,
                hideInModify: true,
                hideInTable: true,
            },
            {
                dataIndex: 'positionUuid',
                title: '岗位',
                valueType: 'select',
                valueEnum: ClientData.dictionary['d4d706cd-1538-456b-90da-d061195c8aa6'],
                hideInAdded: true,
                hideInModify: true,
                hideInTable: true,
            },

            // {
            //     dataIndex: 'overTemperature',
            //     title: '体温状态',
            //     valueType: 'select',
            //     valueEnum: BuiltInData.overTemperature,
            //     width: 150,
            //     hideInSearch: true,
            // },

            commonTableList.createUserName,
            commonTableList.createTime,
            commonTableList.updateUserName,
            commonTableList.updateTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 200,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    return [
                        Permission.findIndex(v => v.uuid === '5d267361-5ff0-4352-8c74-eac5695c9202') !== -1 && (
                            <ModDataButton
                                OptionsEvent={OptionsEvent}
                                key="modify"
                                title="修改"
                                url={url}
                                data={record}
                            />
                        ),
                        Permission.findIndex(v => v.uuid === 'ee9cd696-c44e-4864-832c-dbaca0d75e2c') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }

    return data
}
